package com.xbongbong.paas.enums.bi;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.XbbConstant;
import lombok.Getter;
import lombok.ToString;

import java.util.Objects;

/**
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
@ToString
public enum DataSetTitleEnum {

    // 数据集标题
    NAME("name","firstPinyin", "enum.dataSetTitle.name.name"),
    MEMO("memo","memo", "enum.dataSetTitle.name.memo"),
    CREATOR_ID("creatorId", "creator_id", "enum.dataSetTitle.name.creator_id"),
    //暂时去除更新时间
//    EXECUTE_TIME("executeTime", "execute_time", "enum.dataSetTitle.name.execute_time"),
    //防止排序出错，keySort塞入 update_time
    OPERATE("operate", XbbConstant.UPDATE_TIME, "enum.dataSetTitle.name.operate");

    private String key;
    /**
     * 用于排序时的字段名（与数据库对应）
     */
    private String keySort;
    private String name;

    DataSetTitleEnum(String key, String keySort, String name) {
        this.key = key;
        this.keySort = keySort;
        this.name = name;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    /**
     * 通过key得到数据库内参与排序的字段名 --  即把驼峰转为数据库内字段名
     * @param key
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static String getKeySortByKey(String key){
        for (DataSetTitleEnum cache : values()) {
            if (Objects.equals(key, cache.key)) {
                return cache.keySort;
            }
        }
        return XbbConstant.UPDATE_TIME;
    }
    
    /**
     * 通过字段名获取中文名称
     * @param key
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static String getNameByKey(String key){
        for (DataSetTitleEnum cache : values()) {
            if (Objects.equals(key, cache.key)) {
                return cache.getName();
            }
        }
        return "";
    }
}
